/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tan_anotacionDAOImpl implements orm.dao.Tan_anotacionDAO {
	public Tan_anotacion loadTan_anotacionByORMID(int an_id) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return loadTan_anotacionByORMID(session, an_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion getTan_anotacionByORMID(int an_id) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return getTan_anotacionByORMID(session, an_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion loadTan_anotacionByORMID(int an_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return loadTan_anotacionByORMID(session, an_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion getTan_anotacionByORMID(int an_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return getTan_anotacionByORMID(session, an_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion loadTan_anotacionByORMID(PersistentSession session, int an_id) throws PersistentException {
		try {
			return (Tan_anotacion) session.load(orm.Tan_anotacion.class, new Integer(an_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion getTan_anotacionByORMID(PersistentSession session, int an_id) throws PersistentException {
		try {
			return (Tan_anotacion) session.get(orm.Tan_anotacion.class, new Integer(an_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion loadTan_anotacionByORMID(PersistentSession session, int an_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tan_anotacion) session.load(orm.Tan_anotacion.class, new Integer(an_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion getTan_anotacionByORMID(PersistentSession session, int an_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tan_anotacion) session.get(orm.Tan_anotacion.class, new Integer(an_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion[] listTan_anotacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return listTan_anotacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion[] listTan_anotacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return listTan_anotacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion[] listTan_anotacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_anotacion as Tan_anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tan_anotacion[]) list.toArray(new Tan_anotacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion[] listTan_anotacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_anotacion as Tan_anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tan_anotacion[]) list.toArray(new Tan_anotacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion loadTan_anotacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return loadTan_anotacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion loadTan_anotacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return loadTan_anotacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion loadTan_anotacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tan_anotacion[] tan_anotacions = listTan_anotacionByQuery(session, condition, orderBy);
		if (tan_anotacions != null && tan_anotacions.length > 0)
			return tan_anotacions[0];
		else
			return null;
	}
	
	public Tan_anotacion loadTan_anotacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tan_anotacion[] tan_anotacions = listTan_anotacionByQuery(session, condition, orderBy, lockMode);
		if (tan_anotacions != null && tan_anotacions.length > 0)
			return tan_anotacions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTan_anotacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return iterateTan_anotacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_anotacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BdAnotacionesPersistentManager.instance().getSession();
			return iterateTan_anotacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_anotacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_anotacion as Tan_anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_anotacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_anotacion as Tan_anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion createTan_anotacion() {
		return new orm.Tan_anotacion();
	}
	
	public boolean save(orm.Tan_anotacion tan_anotacion) throws PersistentException {
		try {
			orm.BdAnotacionesPersistentManager.instance().saveObject(tan_anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tan_anotacion tan_anotacion) throws PersistentException {
		try {
			orm.BdAnotacionesPersistentManager.instance().deleteObject(tan_anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tan_anotacion tan_anotacion)throws PersistentException {
		try {
			if(tan_anotacion.getTan_anotadoran() != null) {
				tan_anotacion.getTan_anotadoran().tan_anotacion.remove(tan_anotacion);
			}
			
			if(tan_anotacion.getTan_tipo_anotacionta() != null) {
				tan_anotacion.getTan_tipo_anotacionta().tan_anotacion.remove(tan_anotacion);
			}
			
			if(tan_anotacion.getTan_alumnoal() != null) {
				tan_anotacion.getTan_alumnoal().tan_anotacion.remove(tan_anotacion);
			}
			
			return delete(tan_anotacion);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tan_anotacion tan_anotacion, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tan_anotacion.getTan_anotadoran() != null) {
				tan_anotacion.getTan_anotadoran().tan_anotacion.remove(tan_anotacion);
			}
			
			if(tan_anotacion.getTan_tipo_anotacionta() != null) {
				tan_anotacion.getTan_tipo_anotacionta().tan_anotacion.remove(tan_anotacion);
			}
			
			if(tan_anotacion.getTan_alumnoal() != null) {
				tan_anotacion.getTan_alumnoal().tan_anotacion.remove(tan_anotacion);
			}
			
			try {
				session.delete(tan_anotacion);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tan_anotacion tan_anotacion) throws PersistentException {
		try {
			orm.BdAnotacionesPersistentManager.instance().getSession().refresh(tan_anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tan_anotacion tan_anotacion) throws PersistentException {
		try {
			orm.BdAnotacionesPersistentManager.instance().getSession().evict(tan_anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_anotacion loadTan_anotacionByCriteria(Tan_anotacionCriteria tan_anotacionCriteria) {
		Tan_anotacion[] tan_anotacions = listTan_anotacionByCriteria(tan_anotacionCriteria);
		if(tan_anotacions == null || tan_anotacions.length == 0) {
			return null;
		}
		return tan_anotacions[0];
	}
	
	public Tan_anotacion[] listTan_anotacionByCriteria(Tan_anotacionCriteria tan_anotacionCriteria) {
		return tan_anotacionCriteria.listTan_anotacion();
	}
}
